package com.example.demo.test;

import com.example.demo.domain.ProductFeaturesEnum;
import org.apache.commons.lang3.StringUtils;

public class test04

{
    private static String getPropertyTransaction(String productProperty) {
        StringBuilder translation = new StringBuilder();
        if (StringUtils.isNotBlank(productProperty)) {
            String[] productPropertyList = productProperty.split(",");
            for (String productPropertySingle : productPropertyList) {
                ProductFeaturesEnum productFeaturesEnum = null;
                try {
                    productFeaturesEnum = ProductFeaturesEnum.valueOf(productPropertySingle.toUpperCase());
                } catch (IllegalArgumentException e) {
                    continue;
                }
                switch (productFeaturesEnum) {
                    case WITH_ELECTRICITY:
                        translation.append("内电");
                        break;
                    case WITH_PURE_ELECTRICITY:
                        translation.append("纯电");
                        break;
                    case WITH_MAGNETIC:
                        translation.append("带磁");
                        break;
                    case LIQUID:
                        translation.append("液体");
                        break;
                    case POWDER:
                        translation.append("粉末");
                        break;
                    case GAS:
                        translation.append("气体");
                        break;
                    case NON_LIQUID_COSMETICS:
                        translation.append("非液体化妆品");
                        break;
                    case SPECIAL_SENSITIVE_GOODS:
                        translation.append("特货/敏感货");
                        break;
                    default:
                        break;
                }
                translation.append(",");
            }
        }
        if (translation.length() > 0) {
            return translation.toString().substring(0, translation.length() - 1);
        }
        if(StringUtils.containsOnly(translation,",")){
            return translation.append("空").toString();
        }
        return "";
    }

    public static void main(String[] args) {
        String property = "non_liquid_cosmetics,with_magnetic,liquid,powder,special_sensitive_goods";
//        String property = "";
        getPropertyTransaction(property);
    }
}
